package com.mdd.maduoduo.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.mdd.maduoduo.MyApplication;
import com.mdd.maduoduo.R;
import com.mdd.maduoduo.entity.QueryListEntity;
import com.mdd.maduoduo.utils.CommonAdapter;
import com.mdd.maduoduo.utils.CommonViewHolder;
import com.mdd.maduoduo.utils.GlideUtils;

public class AlreadyReceiveAdapter extends CommonAdapter<QueryListEntity.DataDTO.RecordsDTO> {

    private UpdateStatusListener listener;

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_already_receive;
    }

    public void setListener(UpdateStatusListener listener) {
        this.listener = listener;
    }

    @Override
    protected void bindData(@NonNull CommonViewHolder holder, QueryListEntity.DataDTO.RecordsDTO item, int position) {
        holder.setIsRecyclable(false);
        TextView tvTitle = holder.getView(R.id.tvTitle);
        TextView tvLabel = holder.getView(R.id.tvLabel);
        TextView tvTime = holder.getView(R.id.tvTime);
        TextView tvCode = holder.getView(R.id.tvCode);
        TextView tvSologo = holder.getView(R.id.tvSologo);
        ImageView ivUse = holder.getView(R.id.ivUse);
        ImageView ivLogo = holder.getView(R.id.ivLogo);
        tvCode.setPaintFlags(tvCode.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

        tvTitle.setText(item.stationName);
        if (item.isSharedCode == 1){
            tvLabel.setVisibility(View.VISIBLE);
            tvLabel.setText(item.role);
        }else {
            tvLabel.setVisibility(View.GONE);
        }
        tvTime.setText(item.createTime);
        tvCode.setText(item.pickupCode);
        tvSologo.setText(item.specContent);
        GlideUtils.getInstances().loadRoundImg(MyApplication.getContext(),ivLogo,item.carrierLogo);
        GlideUtils.getInstances().loadNormalImg(MyApplication.getContext(),ivUse,item.functionUrl);
        ivUse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.update(item);
            }
        });
    }

    public interface UpdateStatusListener{
        void update(QueryListEntity.DataDTO.RecordsDTO data);
    }
}
